package com.qidian.mes.produce.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.common.pojo.MESResult;
import com.qidian.mes.pojo.Craft;
import com.qidian.mes.pojo.Process;
import com.qidian.mes.produce.mapper.CraftMapper;
import com.qidian.mes.produce.service.CraftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 陈俊成
 * @Company ccc
 * @Description
 * @Time 2024/10/19 13:39
 */
@Service
public class CraftServiceImpl implements CraftService {
    @Autowired
    CraftMapper craftMapper;
    @Override
    public MESResult queryList(Craft craft,int page,int limit) {
        PageHelper.startPage(page,limit);
        List<Craft> crafts =craftMapper.queryList(craft);

        PageInfo<Craft> projectPageInfo = new PageInfo<>(crafts);
        return MESResult.success(projectPageInfo);

    }

    @Override
    public MESResult addCraft(Craft craft) {
        if (craftMapper.addCraft(craft)==1)
        return MESResult.success();
        return MESResult.error();
    }

    @Override
    public MESResult deleteCraft(int craftRelId) {
        if (craftMapper.updateStatus(craftRelId)==1){
            return MESResult.success();
        }
        return MESResult.error();
    }

    @Override
    public MESResult primaryCraft(Craft craft) {
        if (craftMapper.updateCraftAll(craft)==1){
            return MESResult.success();
        }
        return MESResult.error();
    }

    @Override
    public MESResult getPrimary(int craftRelId) {
        if (craftMapper.getByRelId(craftRelId)!=null){
            return MESResult.success(craftMapper.getByRelId(craftRelId));
        }
        return MESResult.error();
    }
}
